package mobilizator.app.data;

import java.io.File;
import java.io.FileOutputStream;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.os.Environment;
import android.util.Log;

public class IOUtility {
	private static String mPrependFileName = "IMG_";
	  private static final String TAG = "IOUtility";
	  
	  public static boolean saveImageToSDCard(Bitmap b, String appendFileName) {
		    if (b != null) {
		      try {
		        File sdCardFile = Environment.getExternalStorageDirectory();
		        if (sdCardFile.canWrite() == true) {
		          File viewerFile = new File(sdCardFile, "Viewer");
		          viewerFile.mkdirs();
		          File imageFile = new File(viewerFile, mPrependFileName + appendFileName + ".png");
		          FileOutputStream fileStream = new FileOutputStream(imageFile);
		          b.compress(CompressFormat.PNG, 100, fileStream);
		          fileStream.close();
		        } else {
		          Log.e(TAG, "IOUtility - Cannot write to SD Card");
		        }
		        return true;
		      } catch (Exception e) {
		        Log.e(TAG, "IOUtility - Error - " + e);
		        e.printStackTrace();
		      }
		    }
		    return false;
		  }
	  
	  public static Bitmap getBitmapFromSD(String URL) {
		  return null;
	  }
}
